﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Trauberman.SOChat.StarLeaderboard.Data;
using Trauberman.SOChat.StarLeaderboard.Domain;

namespace Trauberman.SOChat.StarLeaderboard.Services
{
	public class UserService : IUserService
	{
		private IDataContext _data;
		public UserService(IDataContext data)
		{
			_data = data;
		}

		public User GetUser(int id)
		{
			return _data.Users.Where(x => x.SOid == id).SingleOrDefault();
		}

		public User AddUser(int userId, string name)
		{
			User user = new User();
			user.SOid = userId;
			user.Name = name;

			_data.Users.Add(user);

			_data.SaveChanges();

			return user;
		}


		public IQueryable<User> GetUsers()
		{
			return _data.Users;
		}
	}
}
